﻿using DAL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace UI
{
    public partial class SelectSeat : System.Web.UI.Page
    {
        public string Movie { get; private set; }
        public string Address { get; private set; }
        public string Time { get; private set; }

        protected void Page_Load(object sender, EventArgs e)
        {
            int columns;
            int rows;
            try
            {
                columns = int.Parse(Request.QueryString["column"]);
                rows = int.Parse(Request.QueryString["row"]);
            }
            catch
            {
                columns = 12;
                rows = 8;
            }
            int movieId = int.Parse(Request.QueryString["MovieId"]);
            int scheduleId = int.Parse(Request.QueryString["ScheduleId"]);
            var movie = Database.Find<Movie>(movieId);
            var schedule = Database.Find<ScheduleInfo>(scheduleId);
            //Movie = Request.QueryString["movie"];
            //Address = Request.QueryString["address"];
            //Time = Request.QueryString["time"];
            Movie = movie.MovieName;
            Address = Request.QueryString["address"];
            Time = Request.QueryString["Time"];
            GenerateSetaTable(columns, rows);
        }

        private void GenerateSetaTable(int columns, int rows)
        {
            var innerHtml = "";
            innerHtml += "<table>";
            for (int i = 0; i <= rows; i++)
            {
                innerHtml += "<tr>";
                for (int j = 1; j <= columns; j++)
                {
                    innerHtml += "<td>";
                    innerHtml += "<img src=\"Images/white.png\"  />";
                    innerHtml += " </td>";
                }
                innerHtml += " </tr>";
            }
            innerHtml += "</table>";
            Site1.InnerHtml = innerHtml;
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            int scheduleId = int.Parse(Request.QueryString["ScheduleId"]);
            var schedule = Database.Find<Schedule>(scheduleId);
            var customer = Database.Find<Customer>(1);

            var order = new Order
            {
                ScheduleId = int.Parse(Request.QueryString["ScheduleId"]),
                OrderAdjustPrice = schedule.SchedulePrice,
                CustomerId = customer.CustomerId,
                OrderBuyDate = DateTime.Now,
            };
            Database.Insert(order);
        }
    }
}